from docx import Document
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.oxml.ns import qn
from docx.shared import Pt, Inches

# 1.创建一个文档
document = Document()
style = document.styles['Normal']
style.font.name = '宋体'
style.element.rPr.rFonts.set(qn('w:eastAsia'), '宋体')

# 2.创建段落
# 标题段落
title = document.add_paragraph('汽车贷款合同')
title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
title.paragraph_format.space_after = Pt(20)
title.style.font.size = Pt(14)
# 内容
content = document.add_paragraph()
content.paragraph_format.first_line_indent = Pt(20)
partA = content.add_run('itcast01')  # 占位符 甲方
content.add_run('（甲方）于')
sign_date = content.add_run('itcast02')  # 占位符 时间
content.add_run('与')
partB = content.add_run('itcast03')  # 占位符 乙方
content.add_run('（乙方）签订汽车贷款合同。乙方需要在')
day = content.add_run('itcast04')  # 占位符 支付时间
content.add_run('天内向甲方支付人民币')
total_money = content.add_run('itcast05')  # 占位符 贷款金额
content.add_run('元来支持甲方购买汽车。甲方需要分为')
times = content.add_run('itcast06')  # 占位符 分期数
content.add_run('期来偿还乙方本金。经过友好协商，甲方需要向乙方一次性支付')
fee = content.add_run('itcast07')  # 占位符 服务费
content.add_run('元作为汽车贷款金融服务费。')

# 署名（签字）
bottom1 = document.add_paragraph('甲方:')
bottom1.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
bottom1.paragraph_format.left_indent = Inches(4)
bottom2 = document.add_paragraph('乙方:')
bottom2.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
bottom2.paragraph_format.left_indent = Inches(4)
bottom3 = document.add_paragraph('日期:    年  月  日')
bottom3.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
bottom3.paragraph_format.left_indent = Inches(4)
# 保存文档
document.save('template.docx')

print('生成合同模板....')
